# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-copas
_pkgname=copas
pkgver=2.0.2
_pkgver=${pkgver//./_}
pkgrel=5
pkgdesc="Coroutine Oriented Portable Asynchronous Services for Lua"
url="https://lunarmodules.github.io/copas/"
arch="noarch"
license="MIT"
depends="lua-socket"
checkdepends="lua5.1-coxpcall lua-sec luajit"
source="$pkgname-$pkgver.tar.gz::https://github.com/keplerproject/$_pkgname/archive/v$_pkgver.tar.gz
	default-tls1.2.patch
	test-certs.patch
	ipv4-only.patch
	skip-broken-test.patch
	"
builddir="$srcdir/$_pkgname-$_pkgver"

_luaversions="5.1 5.2 5.3"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-$_pkgname:_subpackage"
	checkdepends="$checkdepends lua$_v"
done

check() {
	# tests keep running indefinitely
	case "$CARCH" in armv7) return 0;; esac

	local lver; for lver in $_luaversions; do
		msg "Testing on lua$lver"
		make test LUA=lua$lver
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver ${depends//lua-/lua$lver-}"
	[ "$lver" = 5.1 ] && depends="$depends lua5.1-coxpcall"
	install_if="lua$lver $pkgname=$pkgver-r$pkgrel"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$builddir"
	make LUA_DIR="$subpkgdir/usr/share/lua/$lver" install

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
dd83a513fbddb2f0164c3573b417623f5cc556413c4937be7e362f4c1667bad83391143e1bf609480726730ce488c4080e810f2ce12a98a7abb5293993c10182  lua-copas-2.0.2.tar.gz
f775cda7762f7924be8794ea2c77eb49740741a3cf9f67ca7b7e7563868d51f386ed473833e40b673af3aee5660a5e4767f43522bda1e0c38b2bf07c9df183df  test-certs.patch
d65a2d26ff025ec4b7c652bdf179a9f18078f736ec8f9166df077a47ec34cc4731cdeaa984d25c9556f332b36bfd9b4a7e2069284f8b63a4344e8a81b5ad72bc  default-tls1.2.patch
4fb2b65f41869b9729cc4672eebbfb2745a2d01af1cd54341b8306f57510f98e118eac77c77a980f4c8e8b181b6fda150061dc39819269e9ee64bf07656dfd54  ipv4-only.patch
9793138edddc16ef168f07263d1a55f94d1cc973e17c51b3982c6f6cdcdc5a403993db36b65a3cecd73bd3c5d62b94b26031b6595527281370d10070e9e19585  skip-broken-test.patch
"
